<% file_upload_id = "file_upload_#{dom_id(object)}" %>

<alchemy-uploader id="<%= file_upload_id %>">
  <%= form_for [:admin, object], html: {multipart: true, class: 'upload-button'} do |f| %>
    <%= f.file_field file_attribute,
      class: 'fileupload--field',
      name: "#{f.object_name}[#{file_attribute}]",
      id: "replace_#{dom_id(object)}" %>
    <%= label_tag "replace_#{dom_id(object)}", class: "icon_button" do %>
      <%= render_icon "file-upload" %>
    <% end %>
  <% end %>
</alchemy-uploader>

<script type='text/javascript'>
  document.getElementById("<%= file_upload_id %>").addEventListener("Alchemy.upload.successful", (event) => {
    Turbo.visit('<%= redirect_url.html_safe %>');
  })
</script>
